<?php

/**
 * Copyright (C) 2006 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     @license http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

$currentDir = dirname(__FILE__);
require_once($currentDir . "/sensapilityservice.php");
require_once($currentDir . "/utilities.php");


class SensapilityReport extends SensapilityService{
  
  /**
   * Just calls the parent constructor, for SensapilityService
   */
  function SensapilityReport($soapClient, $namespaces, $defaultNamespaceLabel) {
    parent::SensapilityService($soapClient, 
                               $namespaces,
                               $defaultNamespaceLabel);
  }
  
  /**
   * Generates an AdSense For Search channel report
   * @param string $startDate the starting date for the report
   * @param string $endDate the ending date for the report
   * @param boolean $isPredefined whether the date range is predefined (eg.
   * last seven days)
   * @param string $predefinedDateRange the name of the predefined date range, 
   * ignored of $isPredefined is false
   * @param string $outputFormat the format of the report
   * @param string $grouping how the report should be organized, 'Date', 'Channel', 'ChannelAndDate'
   * @param string[] $channels the channels that should be included on this
   * report
   * @return ReportData a report data object representing the requested report
   */
  function generateAfsChannelReport($startDate, 
                                    $endDate, 
                                    $isPredefined, 
                                    $predefinedDateRange, 
                                    $outputFormat, 
                                    $grouping, 
                                    $channels) {
    return $this->__generateChannelReport('AFS',
                                          $startDate, 
                                          $endDate, 
                                          $isPredefined, 
                                          $predefinedDateRange, 
                                          $outputFormat, 
                                          $grouping, 
                                          null, 
                                          $channels); 
  }
  
  /**
   * Generates an AdSense For Content channel report
   * @param string $startDate the starting date for the report
   * @param string $endDate the ending date for the report
   * @param boolean $isPredefined whether the date range is predefined (eg.
   * last seven days)
   * @param string $predefinedDateRange the name of the predefined date range, 
   * ignored of $isPredefined is false
   * @param string $outputFormat the format of the report
   * @param string $grouping how the report should be organized
   * @param string $unit whether to display the report data by page or ad
   * @param string[] $channels the channels that should be included on this
   * report
   * @return ReportData a report data object representing the requested report
   */
  function generateAfcChannelReport($startDate, 
                                    $endDate, 
                                    $isPredefined, 
                                    $predefinedDateRange, 
                                    $outputFormat, 
                                    $grouping, 
                                    $unit, 
                                    $channels) {
    return $this->__generateChannelReport('AFC',
                                          $startDate, 
                                          $endDate, 
                                          $isPredefined, 
                                          $predefinedDateRange, 
                                          $outputFormat, 
                                          $grouping, 
                                          $unit, 
                                          $channels);
  }
  
  /**
   * Generates an AdSense For Search channel report
   * @param string $serviceType what service this report is for
   * @param string $startDate the starting date for the report
   * @param string $endDate the ending date for the report
   * @param boolean $isPredefined whether the date range is predefined (eg.
   * last seven days)
   * @param string $predefinedDateRange the name of the predefined date range, 
   * ignored of $isPredefined is false
   * @param string $outputFormat the format of the report
   * @param string $grouping how the report should be organized
   * @param string $unit whether to display the report data by page or ad
   * @param string[] $channels the channels that should be included on this
   * report
   * @return ReportData a report data object representing the requested report
   */
  function __generateChannelReport($serviceType,
                                   $startDate, 
                                   $endDate, 
                                   $isPredefined, 
                                   $predefinedDateRange, 
                                   $outputFormat, 
                                   $grouping, 
                                   $unit, 
                                   $channels) {
    $ns = $this->defaultNamespaceLabel;
    $returnValue = null;
    $callParameters = array();
    $callParameters[$ns . ':report'] = array();
    $callParameters[$ns . ':report']['attributes'] = 
        array("xsi:type" => $ns . ':' . $serviceType . 'ChannelReport');

    $isPredefined = ConvertToBooleanString($isPredefined);

    $callParameters[$ns . ':report']['value'] = array();
    $dateRange = array($ns . ':endDate' => $endDate,
                       $ns . ':isPredefined' => $isPredefined,
                       $ns . ':predefinedDateRange' => 
                         array('value' => 
                           array('value' => $predefinedDateRange)),
                       $ns . ':startDate' => $startDate);
    $callParameters[$ns . ':report']['value'][$ns . ':dateRange'] = 
        array('value' => $dateRange);
    $callParameters[$ns . ':report']['value'][$ns . ':outputFormat'] = 
        array('value' => array('value' => $outputFormat));
    // cheat array key syntax by padding keys with whitespace
    // since arrayToXml() will strip this out when converting to a string
    $tagPad = "";
    $keys = array_keys($channels);
    foreach ( $keys as $key ) {
      $callParameters[$ns . ':report']['value'][$tagPad . $ns . ':channels'] = 
          $channels[$key];
      $tagPad .= " ";
    }
    if ('AFC' == $serviceType) {
      $callParameters[$ns . ':report']['value'][$ns . ':unit'] = 
          array('value' => array('value' => $unit));
    }
    $callParameters[$ns . ':report']['value'][$ns . ':grouping'] = 
        array('value' => array('value' => $grouping));

    return parent::doSoapCall('generateReport',
                              ArrayToXml($callParameters),
                              $this->__soapClient->namespaces[$ns],
                              true,
                              0,
                              false);
  } 

  /**
   * Generates an aggregate earnings report for AdSense For Content
   * @param string $startDate the starting date for the report
   * @param string $endDate the ending date for the report
   * @param boolean $isPredefined whether the date range is predefined (eg.
   * last seven days)
   * @param string $predefinedDateRange the name of the predefined date range, 
   * ignored of $isPredefined is false
   * @param string $outputFormat the format of the report
   * @param string $unit whether to display the report data by page or ad
   * @return ReportData a report data object representing the requested report
   */
  function generateAfcAggregateReport($startDate, 
                                      $endDate, 
                                      $isPredefined, 
                                      $predefinedDateRange, 
                                      $outputFormat, 
                                      $unit) {
    $ns = $this->defaultNamespaceLabel;
    $returnValue = null;
    $callParameters = array();
    $callParameters[$ns . ':report'] = array();
    $callParameters[$ns . ':report']['attributes'] = 
        array("xsi:type" => $ns . ':AFCAggregateReport');

    $isPredefined = ConvertToBooleanString($isPredefined);

    $callParameters[$ns . ':report']['value'] = array();
    $dateRange = array($ns . ':endDate' => $endDate,
                       $ns . ':isPredefined' => $isPredefined,
                       $ns . ':predefinedDateRange' =>
                         array('value' =>
                           array('value' =>
                             $predefinedDateRange)),
                       $ns . ':startDate' => $startDate);
    $callParameters[$ns . ':report']['value'][$ns . ':dateRange'] = 
        array('value' => $dateRange);
    $callParameters[$ns . ':report']['value'][$ns . ':outputFormat'] = 
        array('value' => array('value' => $outputFormat));
    $callParameters[$ns . ':report']['value'][$ns . ':unit'] = 
        array('value' => array('value' => $unit));

    return parent::doSoapCall('generateReport',
                              ArrayToXml($callParameters),
                              $this->__soapClient->namespaces[$ns],
                              true,
                              0,
                              false);
  } 

  /**
   * Generates an aggregate earnings report for AdSense For Search
   * @param string $startDate the starting date for the report
   * @param string $endDate the ending date for the report
   * @param boolean $isPredefined whether the date range is predefined (eg.
   * last seven days)
   * @param string $predefinedDateRange the name of the predefined date range, 
   * ignored of $isPredefined is false
   * @param string $outputFormat the format of the report
   * @return ReportData a report data object representing the requested report
   */
  function generateAfsAggregateReport($startDate, 
                                      $endDate, 
                                      $isPredefined, 
                                      $predefinedDateRange, 
                                      $outputFormat) {
    return $this->__generateAfsReport('Aggregate',
                                      $startDate, 
                                      $endDate, 
                                      $isPredefined, 
                                      $predefinedDateRange, 
                                      $outputFormat);
  }

  /**
   * Generates an earnings report for AdSense For Search based on query
   * @param string $startDate the starting date for the report
   * @param string $endDate the ending date for the report
   * @param boolean $isPredefined whether the date range is predefined (eg.
   * last seven days)
   * @param string $predefinedDateRange the name of the predefined date range, 
   * ignored of $isPredefined is false
   * @param string $outputFormat the format of the report
   * @return ReportData a report data object representing the requested report
   */  
  function generateAfsQueryReport($startDate, 
                                  $endDate, 
                                  $isPredefined, 
                                  $predefinedDateRange, 
                                  $outputFormat) {
    return $this->__generateAfsReport('Query',
                                      $startDate, 
                                      $endDate, 
                                      $isPredefined, 
                                      $predefinedDateRange, 
                                      $outputFormat);
  }

  /**
   * Generates an aggregate and query reports for AdSense For Search
   * @param string $rptType if this is an aggregate or query report
   * @param string $startDate the starting date for the report
   * @param string $endDate the ending date for the report
   * @param boolean $isPredefined whether the date range is predefined (eg.
   * last seven days)
   * @param string $predefinedDateRange the name of the predefined date range, 
   * ignored of $isPredefined is false
   * @param string $outputFormat the format of the report
   * @return ReportData a report data object representing the requested report
   */
  function __generateAfsReport($rptType,
                               $startDate, 
                               $endDate, 
                               $isPredefined, 
                               $predefinedDateRange, 
                               $outputFormat) {
    $ns = $this->defaultNamespaceLabel;
    $returnValue = null;
    $callParameters = array();
    $callParameters[$ns . ':report'] = array();
    $callParameters[$ns . ':report']['attributes'] = 
        array("xsi:type" => $ns . ':AFS' . $rptType . 'Report');

    $isPredefined = ConvertToBooleanString($isPredefined);
    $callParameters[$ns . ':report']['value'] = array();
    $dateRange = array($ns . ':endDate' => $endDate,
                       $ns . ':isPredefined' => $isPredefined,
                       $ns . ':predefinedDateRange' => 
                         array('value' =>
                           array('value' => $predefinedDateRange)),
                       $ns . ':startDate' => $startDate);
    $callParameters[$ns . ':report']['value'][$ns . ':dateRange'] = 
        array('value' => $dateRange);
    $callParameters[$ns . ':report']['value'][$ns . ':outputFormat'] = 
        array('value' => array('value' => $outputFormat));

    return parent::doSoapCall('generateReport',
                              ArrayToXml($callParameters),
                              $this->__soapClient->namespaces[$ns],
                              true,
                              0,
                              false);
  }
  
  /**
   * Generates an aggregate AFC report for the publisher's activity on the 
   *  developer's site only.
   * @param string $startDate the starting date for the report
   * @param string $endDate the ending date for the report
   * @param boolean $isPredefined whether the date range is predefined (eg.
   * last seven days)
   * @param string $predefinedDateRange the name of the predefined date range, 
   * ignored of $isPredefined is false
   * @param string $outputFormat the format of the report
   * @param string $unit whether to display the report data by page or ad
   * @return ReportData a report data object representing the requested report
   */
  function generateAfcSiteReport($startDate, $endDate, $isPredefined,
                                 $predefinedDateRange, $outputFormat,
                                 $unit) {
    $ns = $this->defaultNamespaceLabel;
    $returnValue = null;
    $callParameters = array();
    $callParameters[$ns . ':report'] = array();
    $callParameters[$ns . ':report']['attributes'] = 
        array("xsi:type" => $ns . ':AFCSiteReport');

    $isPredefined = ConvertToBooleanString($isPredefined);
    $callParameters[$ns . ':report']['value'] = array();
    $dateRange = array($ns . ':endDate' => $endDate,
                       $ns . ':isPredefined' => $isPredefined,
                       $ns . ':predefinedDateRange' => 
                         array('value' =>
                           array('value' => $predefinedDateRange)),
                       $ns . ':startDate' => $startDate);
    $callParameters[$ns . ':report']['value'][$ns . ':dateRange'] = 
        array('value' => $dateRange);
    $callParameters[$ns . ':report']['value'][$ns . ':outputFormat'] = 
        array('value' => array('value' => $outputFormat));
    $callParameters[$ns . ':report']['value'][$ns . ':unit'] =
        array('value' => array('value' => $unit));

    return parent::doSoapCall('generateReport',
                              ArrayToXml($callParameters),
                              $this->__soapClient->namespaces[$ns],
                              true,
                              0,
                              false);
  }
  
  /**
   * Generates an aggregate AFS report for the publisher's activity on the 
   *  developer's site only.
   * @param string $startDate the starting date for the report
   * @param string $endDate the ending date for the report
   * @param boolean $isPredefined whether the date range is predefined (eg.
   * last seven days)
   * @param string $predefinedDateRange the name of the predefined date range, 
   * ignored of $isPredefined is false
   * @param string $outputFormat the format of the report
   * @return ReportData a report data object representing the requested report
   */
  function generateAfsSiteReport($startDate, $endDate, $isPredefined,
                                 $predefinedDateRange, $outputFormat) {
    $ns = $this->defaultNamespaceLabel;
    $returnValue = null;
    $callParameters = array();
    $callParameters[$ns . ':report'] = array();
    $callParameters[$ns . ':report']['attributes'] = 
        array("xsi:type" => $ns . ':AFSSiteReport');

    $isPredefined = ConvertToBooleanString($isPredefined);
    $callParameters[$ns . ':report']['value'] = array();
    $dateRange = array($ns . ':endDate' => $endDate,
                       $ns . ':isPredefined' => $isPredefined,
                       $ns . ':predefinedDateRange' => 
                         array('value' =>
                           array('value' => $predefinedDateRange)),
                       $ns . ':startDate' => $startDate);
    $callParameters[$ns . ':report']['value'][$ns . ':dateRange'] = 
        array('value' => $dateRange);
    $callParameters[$ns . ':report']['value'][$ns . ':outputFormat'] = 
        array('value' => array('value' => $outputFormat));

    return parent::doSoapCall('generateReport',
                              ArrayToXml($callParameters),
                              $this->__soapClient->namespaces[$ns],
                              true,
                              0,
                              false);
  }
}
?>
